package com.zrrd.jt_admin.image.controller;


import com.zrrd.jt_admin.common.entity.ImageClass;
import com.zrrd.jt_admin.common.response.ResponseResult;
import com.zrrd.jt_admin.common.vo.ImageClassPageVo;
import com.zrrd.jt_admin.image.service.ImageClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangYK
 * @since 2024-07-03
 */
@Api(tags = "相册管理-接口文档")
@RestController
@RequestMapping("admin/imageClass")
@ResponseBody
public class ImageClassController {

    @Resource
    private ImageClassService imageClassService;

    @ApiOperation(value = "1、相册分类列表")
    @GetMapping("{page}")
    public ResponseResult findByPage(@PathVariable Integer page,
                                     @RequestParam(required = false) Integer limit) {
        if (limit == null){
            limit = 5;
        }
        ImageClassPageVo imageClassPageVo = imageClassService.findByPage(page,limit);
        return ResponseResult.queryResponse(imageClassPageVo);
    }

    @ApiOperation(value = "2、增加相册分类")
    @PostMapping
    public ResponseResult addImageClass(@RequestBody ImageClass imageClass) {
        boolean flag = imageClassService.save(imageClass);

        return ResponseResult.addResponse(flag);
    }

    @ApiOperation(value = "3、修改相册分类")
    @PutMapping
    public ResponseResult updateImageClass(@RequestBody ImageClass imageClass) {
        boolean flag = imageClassService.updateById(imageClass);
        return ResponseResult.updateResponse(flag);
    }

    @ApiOperation(value = "4、删除相册分类")
    @DeleteMapping("{id}/delete")
    public ResponseResult deleteImageClass(@PathVariable Integer id) {
        boolean flag = imageClassService.removeById(id);
        return ResponseResult.removeResponse(flag);
    }

}

